//
//  BaseNavigationController.m
//  PandaTakeaway
//
//  Created by smufs on 2017/5/17.
//  Copyright © 2017年 李冰. All rights reserved.
//

#import "BaseNavigationController.h"

@interface BaseNavigationController ()

@end

@implementation BaseNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

+(void)initialize {

    // 设置整个项目的navigationBar属性
//    UINavigationBar *bar = [UINavigationBar appearance];
    // 背景色
//    bar.barTintColor = ;
//    bar.tintColor = kColor(colorWithHexString:@"FFFFFF");
    [[UIBarButtonItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:kBlackColor,NSForegroundColorAttributeName, [UIFont systemFontOfSize:14],NSFontAttributeName , nil] forState:0];
    [[UINavigationBar appearance] setBackIndicatorImage:[UIImage imageNamed:@"navigationButtonReturn"]];
    [[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[UIImage imageNamed:@"navigationButtonReturn"]];
    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -2) forBarMetrics:UIBarMetricsDefault];
    [[UINavigationBar appearance] setTranslucent:NO];
    // 标题颜色
//    bar.titleTextAttributes = @{NSForegroundColorAttributeName:kColor(whiteColor),
//                                NSFontAttributeName:[UIFont boldSystemFontOfSize:18.0]};
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.viewControllers.count > 0) {
        
        viewController.hidesBottomBarWhenPushed = YES;
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        NSString *imageName = viewController.preferredStatusBarStyle == UIStatusBarStyleDefault ? @"ic_top_back" : @"ic_top_back";
        [button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
        // [button setImage:[UIImage imageNamed:@""] forState:UIControlStateHighlighted];
        button.lb_size = CGSizeMake(30, 30);
        button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    }
    
    [super pushViewController:viewController animated:animated];
}

- (void)back
{
    [self popViewControllerAnimated:YES];
}

- (UIViewController *)childViewControllerForStatusBarStyle {

    return self.topViewController;
}

@end
